package com.weddingee.dao.base;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.weddingee.exception.DBException;
import com.weddingee.util.DatabaseConnectionManager;
import com.weddingee.util.ProxoolDatabaseConnectionManager;


public class BaseDao{
	protected final transient Log log = LogFactory.getLog(getClass());
	protected Connection getConn()throws DBException{
		Connection conn = ProxoolDatabaseConnectionManager.getConnection();
		if( null == conn ){
			throw new DBException("获取连接失败.");
		}
		return conn;
	}
	
	protected void closeConn(Connection conn)throws DBException{
		if( null != conn){
			try {
				conn.close();
				conn = null;
			} catch (SQLException e) {
				throw new DBException("关闭连接失败.");
			}
		}
	}
	
	protected void closeStatement(Statement stm)throws DBException{
		if( null != stm){
			try {
				stm.close();
				stm = null;
			} catch (SQLException e) {
				throw new DBException("关闭Statement失败.");
			}
		}
	}
}